#include "CSetNameCommand.h"
#include "CUserInterface.h"
#include "CLevelEditor.h"
#include "IGUITreeCtrl.h"


extern CGlobals* g;
extern CUserInterface* ui;
extern CLevelEditor* editor;

CSetNameCommand::CSetNameCommand (int id, stringw oldName, stringw newName)
{
	m_id = id;
	m_oldName = oldName;
	m_newName = newName;
	setDescription(L"change Name");
}

static void setName (int id, stringw name)
{
	TreeNode* treeNode = ui->m_sceneGraphTree->FindNode(id);
	treeNode->Text = stringw(id) + L" - " + name;
	treeNode->LowerText = treeNode->Text;
	treeNode->LowerText.make_lower();
	editor->getSceneObjectFromID(id)->m_UserData->setAttribute("Name", name.c_str());
}

void CSetNameCommand::redo ()
{
	setName(m_id, m_newName);
}

void CSetNameCommand::undo ()
{
	setName(m_id, m_oldName);
}
